#测试注册页面
from time import sleep
from common.Untils import WJDriver
from selenium.webdriver.common.by import By

class WJRegister:
    url=""
    driver=""
    def __init__(self):
        self.url="http://8.155.1.153:8081/user/register"
        self.driver=WJDriver.driver
        self.driver.get(self.url)
    #1.注册成功
    def RegisterSuccess(self):
        #测试场景一：输入姓名，未注册过的账号，六位以上的密码，密码确认，点击注册账户按钮
        #输入姓名
        self.driver.find_element(By.CSS_SELECTOR, "#name").send_keys("zhangsan"+WJDriver.name)
        #输入登录账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan"+WJDriver.name)
        #输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        #输入确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#rePassword").send_keys("123456")
        #截图
        WJDriver.getScreenShot()
        #点击注册账户
        self.driver.find_element(By.CSS_SELECTOR, "#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button").click()

        # 2.注册失败
    def RegisterFailed(self):
        self.driver.get(self.url)

        #测试场景二：输入注册过的账号，其他正常填写
        # 输入姓名
        self.driver.find_element(By.CSS_SELECTOR, "#name").send_keys("zhangsan" + WJDriver.name)
        # 输入登录账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan" )
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        # 输入确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#rePassword").send_keys("123456")
        # 截图
        WJDriver.getScreenShot()
        # 点击注册账户
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button").click()
        #sleep(1)

        #测试场景三：输入未注册过的账号，密码与确认密码不一致，其他正常填写
        #清空先前输入
        self.driver.refresh()
        #sleep(1)
        # 输入姓名
        self.driver.find_element(By.CSS_SELECTOR, "#name").send_keys("zhangsan" + WJDriver.name)
        # 输入登录账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan"+ WJDriver.name)
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        # 输入确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#rePassword").send_keys("1234567")
        # 截图
        WJDriver.getScreenShot()
        # 点击注册账户
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button").click()
        #sleep(1)

        #测试场景四：输入未注册过的账号，密码长度小于六位，其他正常填写
        # 清空先前输入
        # self.driver.find_element(By.CSS_SELECTOR, "#name").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#rePassword").clear()
        self.driver.refresh()
        #sleep(1)
        # 输入姓名
        self.driver.find_element(By.CSS_SELECTOR, "#name").send_keys("zhangsan" + WJDriver.name)
        # 输入登录账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan" + WJDriver.name)
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("12345")
        # 输入确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#rePassword").send_keys("12345")
        # 截图
        WJDriver.getScreenShot()
        # 点击注册账户
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button").click()
        #sleep(1)

        #测试场景五：不填写姓名，其他均正常填写
        # 清空先前输入
        self.driver.refresh()
        #sleep(1)
        # 输入登录账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan" + WJDriver.name)
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        # 输入确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#rePassword").send_keys("123456")
        # 截图
        WJDriver.getScreenShot()
        # 点击注册账户
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button").click()
        #sleep(1)

        #测试场景六：不填写登录账号，其他均正常填写
        # 清空先前输入
        self.driver.refresh()
        #sleep(1)
        # 输入姓名
        self.driver.find_element(By.CSS_SELECTOR, "#name").send_keys("zhangsan" + WJDriver.name)
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        # 输入确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#rePassword").send_keys("123456")
        # 截图
        WJDriver.getScreenShot()
        # 点击注册账户
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button").click()
        #sleep(1)

        #测试场景七：不填写密码，其他均正常填写
        # 清空先前输入
        self.driver.refresh()
        #sleep(1)
        # 输入姓名
        self.driver.find_element(By.CSS_SELECTOR, "#name").send_keys("zhangsan" + WJDriver.name)
        # 输入登录账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan" + WJDriver.name)
        # 输入确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#rePassword").send_keys("123456")
        # 截图
        WJDriver.getScreenShot()
        # 点击注册账户
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button").click()
        #sleep(1)

        #测试场景八：不填写密码确认，其他均正常填写
        #清空先前输入
        self.driver.refresh()
        #sleep(1)
        # 输入姓名
        self.driver.find_element(By.CSS_SELECTOR, "#name").send_keys("zhangsan" + WJDriver.name)
        # 输入登录账号
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangsan"+ WJDriver.name)
        # 输入密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        # 截图
        WJDriver.getScreenShot()
        # 点击注册账户
        self.driver.find_element(By.CSS_SELECTOR,"#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button").click()
        #sleep(1)
# register=WJRegister()
# register.RegisterSuccess()
# register.RegisterFailed()
